package com.iwomy.envpro.platform.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iwomy.envpro.admin.api.entity.SysDept;
import com.iwomy.envpro.admin.api.feign.RemoteDeptService;
import com.iwomy.envpro.common.security.util.SecurityUtils;
import com.iwomy.envpro.platform.VO.AirGridMemberVO;
import com.iwomy.envpro.platform.entity.AirGridMemberEntity;
import com.iwomy.envpro.platform.entity.BasicVideoSurveillanceEntity;
import com.iwomy.envpro.platform.mapper.AirGridMemberMapper;
import com.iwomy.envpro.platform.service.AirGridMemberService;
import com.iwomy.envpro.platform.utils.DeptFillUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 人员管理
 *
 * @author pig
 * @date 2023-08-26 10:16:51
 */
@Service
public class AirGridMemberServiceImpl extends ServiceImpl<AirGridMemberMapper, AirGridMemberEntity> implements AirGridMemberService {
	@Override
	public boolean addAirGridMember(AirGridMemberEntity airGridMember) {
		return false;
	}

	@Resource
	private RemoteDeptService remoteDeptService;

	@Override
	public Page getAirGridMemberPage(Page page, AirGridMemberEntity airGridMember) {
		List data = remoteDeptService
				.listByDeptId(ObjectUtil.isNull(airGridMember.getDeptId())?
						SecurityUtils.getUser().getDeptId() :airGridMember.getDeptId()).getData();
		airGridMember.setDeptId(null);
		LambdaQueryWrapper<AirGridMemberEntity> wrapper = Wrappers.lambdaQuery(airGridMember);

		wrapper.in(ObjectUtil.isNotEmpty(data), AirGridMemberEntity::getDeptId, data);
		page = this.page(page, wrapper);

		DeptFillUtils.fill(page);
		return page;
	}
}